//******************************************************************************
// Date: 2020-4-14
// Author: Che Yuzhi
// ID: 201928000907028
// Description:
// 	Homework2
// 	- Construct a formula with any non-linear shape (ploynominal, Gaussian, 
// 	Landau, or Possion ..)
// 	- Produce three histograms with the statistics of 100, 1000, and 10000, 
// 	respectively.
// 	Compare the differences of the different staticstical histograms.
// 	Try to vary the bin width to check the changes.
// 	- Plot error bars in each histogram.
// 	- Get the mean, RMS and skewness of each histogram.
// 	Show them in the plot and Print them out in the terminal.
// 	- Try to make your histogram plots pretty.
//******************************************************************************
{
void funcPrintInfo(int stat, TH1D* hist);
void funcSetStyle();
funcSetStyle();

/********  Create TF1  ********/
TF1* ploynominal = new TF1("ploynominal","x^2/25",-5,5);
TF1* gaussian = new TF1("gaussian","TMath::Gaus(x)",-5,5);
TF1* landau = new TF1("landau","TMath::Landau(x)",-5,5);
TF1* possion = new TF1("possion","TMath::Poisson(x,1)",-5,5);

/********  Create three Canvas to Draw  ********/
TCanvas* CanvHist[3] = {0, 0, 0};
for(int i=0;i<3;i++){
	CanvHist[i] = new TCanvas();  // 这样创建就是不好命名，说不定可以用字符串数组
}
TH1D* hist_1 = new TH1D("hist_1",";X;Y",100,-5,5);

/********  Fill hist and Draw  ********/
CanvHist[0]->cd(); //// 进入所选的Pad
hist_1->FillRandom("gaus",100);
hist_1->DrawClone("E1");
funcPrintInfo(100, hist_1);

CanvHist[1]->cd();
hist_1->FillRandom("gaus",900);
hist_1->DrawClone("E1");
funcPrintInfo(1000, hist_1);

CanvHist[2]->cd(); 
hist_1->FillRandom("gaus",9000);
hist_1->DrawClone("E1");
funcPrintInfo(10000, hist_1);

for(int i=0;i<3;i++){
	CanvHist[i]->Draw();
}

}


//******************************************************************************
// Summary: Print the mean, RMS and skewness of a histogram in the terminal.
// Parameters:
//     stat: Statistic of the input histogram
//     hist: Pointer of the input histogram
//******************************************************************************
void funcPrintInfo(int stat, TH1D* hist){
	cout << "Statistics " << stat << "  :  " << endl;
	cout << "           ";
	cout << "Mean = " << hist->GetMean() << " ;  ";
	cout << "RMS  = " << hist->GetRMS() << " ;  ";
	cout << "Skewness = " << hist->GetSkewness() << " ;" << endl;
}


//******************************************************************************
// Summary: Set the plot style
//******************************************************************************
void funcSetStyle(){
	TStyle* beautyDraw = new TStyle("beautyDraw",
									"Style for these Histograms");
	beautyDraw->SetCanvasBorderMode(0);
	beautyDraw->SetOptStat("srm");
	beautyDraw->SetMarkerStyle(20);
	beautyDraw->SetMarkerColor(kRed); // 注意这里不能用string，不要加双引号
	beautyDraw->SetMarkerSize(0.5);
	beautyDraw->SetLabelSize(0.04);
	beautyDraw->SetTitleSize(0.04,"xy");
	//gROOT->SetStyle("beautyDraw");
	beautyDraw->cd();
}

